/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.asu.cse360.client.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * this class generates a md5 password based off of what the input is
 * @author nadimhoque
 */
public class PasswordUtils {
    public static String getMD5Password(char[] passwordChars){
       String plainTextPassword = String.valueOf(passwordChars);
       return getMD5Password(plainTextPassword);
    }

    public static String getMD5Password(String plainTextPassword) {
        String password = plainTextPassword;
        try {
           MessageDigest md5 = MessageDigest.getInstance("MD5");
           md5.update(password.getBytes());
           byte[] passwordBytes = md5.digest();
           password = "";
           for (int i = 0; i < passwordBytes.length; i++) {
               password += Integer.toHexString((0x000000ff & passwordBytes[i]) | 0xffffff00).substring(6);
           }
       } catch (NoSuchAlgorithmException ex) {
       }
       return password;
    }
}
